package graphics.rasterizing.camera;

import static org.junit.Assert.assertTrue;
import static util.MatrixOperationsF.add;
import static util.MatrixOperationsF.ar;
import static util.MatrixOperationsF.multiply;
import static util.MatrixOperationsF.negate;
import static util.MatrixOperationsF.print;
import static util.TestFunctions.almost_equal;
import static util.TestFunctions.array_equal;

import org.junit.Test;

public class _CameraPositionTestCase {
	@Test
	public void CreationTest() {
//		CameraPosition camera = new CameraPosition(ar(0, 0, -1, 1), ar(0, 1, 0,
//				1), ar(0, 0, -1, 1));
		assertTrue(true);
	}

	@Test
	public void testGetters() {
		float[] one, two, three;
		one = ar(0, 0, -1, 1);
		two = ar(0, 1, 0, 1);
		three = ar(0, 0, -1, 1);
		CameraPosition camera = new CameraPosition(one, two, three);
		assertTrue(array_equal(one, camera.getOrigin()));
		assertTrue(array_equal(two, camera.getOrientation()));
		assertTrue(array_equal(three, camera.getViewDiretion()));
	}

	@Test
	public void testNoTransformation() {
		float[] origin, orientation, direction;
		origin = ar(0, 0, 0, 1);// at the origin
		orientation = ar(0, 1, 0, 1);
		direction = ar(0, 0, -1, 1);// along the negative z-axis
		CameraPosition camera = new CameraPosition(origin, orientation,
				direction);
		float[][] transformation = camera.matrix();
		float[] apoint = ar(123, 0.44f, 22.9191f, 1);
		assertTrue(array_equal(apoint, multiply(transformation, apoint)));
	}

	@Test
	public void originChangeTest() {
		float[] origin, orientation, direction;
		origin = ar(0, 10, 0, 1);// at the origin
		orientation = ar(0, 1, 0, 1);
		direction = ar(0, 0, -1, 1);// along the negative z-axis
		CameraPosition camera = new CameraPosition(origin, orientation,
				direction);
		float[][] transformation = camera.matrix();
		float[] apoint = ar(123, 0.44f, 22.9191f, 1);
		System.out.println(print(multiply(transformation, apoint)));
		assertTrue(almost_equal(add(apoint, negate(origin)),
				multiply(transformation, apoint), 3));
	}
}
